doc.addEventListener('startScan',function(event) {  
  
         if(scan) {  
  
                  startScan(event.detail.notClose);  
  
         }  
  
});  
  
//停止扫描事件  
  
doc.addEventListener('endScan',function() {  
  
         if(scan) {  
  
                   scan.cancel();  
  
         }  
  
});  
  
VarflashOpen=false;  
  
// 开启闪光灯事件  
  
doc.addEventListener('setFlash',function() {  
  
         if(scan) {  
  
                   flashOpen= !flashOpen;  
  
                   scan.setFlash(flashOpen);  
  
         }  
  
});     
    
    function startScan(notClose) {
      
        _notClose = notClose;  
      
        //若是需要将结果返回文件  
      
        scan.start({  
      
            conserve: true,  
      
            filename: _filePath  
      
        });  
      
    }  
      
      
      
    functioninitScan(view) {  
      
        var filter = [plus.barcode.CODE128, plus.barcode.EAN13];
      
        var scan = new plus.barcode.Barcode('divReg');  
      
        scan = new plus.barcode.Barcode(view,filter);  
      
        scan.onmarked = onmarked;
      
    }  
      
      
      
    functiononmarked(type, result, file) {  
      
        switch (type) {  
      
            caseplus.barcode.QR:  
      
                type = "QR";  
      
            break;  
      
            caseplus.barcode.EAN13:  
      
                type = "EAN13";  
      
            break;  
      
            caseplus.barcode.EAN8:  
      
                type = "EAN8";  
      
            break;  
      
            default:  
      
            type = "其它";  
      
            break;  
      
        }  
      
        varself = plus.webview.currentWebview();  
      
        varopener = self.opener();  
      
        scan.cancel();  
      
        mui.fire(opener, 'endScan', {  
      
            result: result,  
      
            file: file  
      
        });  
      
        //继续扫描，不关闭扫描窗口  
      
        if (_notClose) {  
      
            setTimeout(function() {  
      
                startScan(true);  
      
            }, 1000);  
      
        } else {  
      
            self.hide();  
      
        }  
      
    }
    
    function($, owner) {  
      
        var_scanWindow = null;  
      
        owner.InitScan = function(filePath) {  
      
            _scanWindow = mui.preload({  
      
                url: '/view/CommonHelper/ScanCanvas.html',  
      
                id: 'scanCanvas',  
      
                waiting: {  
      
                    autoShow: true,  
      
                    title: '正在加载...'  
      
                },  
      
                extras: {  
      
                    filePath: filePath  
      
                }  
      
            });  
      
        };  
      
      
      
        /** 
     
         * 开始扫描 
     
         * @param {Object} isContinue 是否连续扫描 
     
         */  
      
        owner.BeginScan = function(isContinue) {  
      
            mui.fire(_scanWindow, 'startScan', {  
      
                notClose: isContinue  
      
            });  
      
            _scanWindow.show();  
      
        };  
      
      
      
        /** 
     
         *结束扫描 
     
         */  
      
        owner.EndScan = function() {  
      
            mui.fire(_scanWindow, 'endScan');  
      
        }  
      
    }(mui, window.BarcodeUtil = {}));  